package cn.adelyn.blog.file.dao;

import cn.adelyn.blog.file.dao.mapper.ShareInfoMapper;
import cn.adelyn.blog.file.pojo.model.ShareInfoModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ShareInfoDAOService {

    @Autowired
    ShareInfoMapper shareInfoMapper;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public void insertShareInfoDb(ShareInfoModel shareInfoModel) {
        shareInfoMapper.insert(shareInfoModel);
    }

    public void deleteShareInfoDb(Long shareId) {
        shareInfoMapper.deleteById(shareId);
    }

    public void insertShareInfoRedis(String shareId, String fileId, Long duration, TimeUnit timeUnit) {
        stringRedisTemplate.opsForValue().set(shareId, fileId, duration, timeUnit);
    }

    public String getShareInfoRedis(String shareId) {
        return stringRedisTemplate.opsForValue().get(shareId);
    }
}
